<?php
/**
 * MongoDig
 *
 * @copyright  Copyright (c) 2010 lanyanguang (http://www.lanyg.com)
 * @license    GNU General Public License 2.0
 * @version    $Id$
 */

/** 初始化 */
require_once 'init.php';

//判断是否登录
if(!$user_id = is_login()){
	echo 'undefined';
	exit;
}

//投票
$topic_id = $_POST['topic_id'];

include_logic('vote');
include_logic('topic');
$vote = array(
	'topic_id'=>$topic_id,
	'user_id'=>$user_id,
	'y2n'=>1,
	'entry_time'=>time()
);
vote_insert($vote);
$topic_count = vote_find(array('topic_id'=>$topic_id,'y2n'=>1))->count();
$vote_count = vote_find(array('topic_id'=>$topic_id,'y2n'=>-1))->count();
$the_score = $topic_count - $vote_count;
topic_update(array('_id'=>new MongoId($topic_id)),array('$set'=>array('score'=>$the_score)));
echo $the_score;